<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax操作</title>
    <script src="js/jquery-1.12.4.js" type="text/javascript"></script>
</head>
<body>

    <input id="btn1" type="button" value="jquery ajax get 请求">
    <input id="btn2" type="button" value="jquery ajax post 请求">
    <input id="btn3" type="button" value="jquery get 请求">
    <input id="btn4" type="button" value="jquery post 请求">
    <script type="text/javascript">
        $(function () {
            $("#btn1").click(function () {
                $.ajax({
                    url:"servlet1",
                    type:"get",
                    data:"username=张三&password=123",
                    contentType:"application/x-www-form-urlencoded",
                    dataType:"html",
                    success:function (data) {
                        alert(data);
                    }
                });
            });
            $("#btn2").click(function () {
                $.ajax({
                    url:"servlet1",
                    type:"post",
                    data:"username=张三&password=123",
                    contentType:"application/x-www-form-urlencoded",
                    dataType:"html",
                    success:function (data) {
                        alert(data);
                    }
                });
            });
            $("#btn3").click(function () {
                $.get("servlet1",function (data) {
                    alert(data);
                },"html");
            });
            $("#btn4").click(function () {
                $.post("servlet1",{"username":"李思","password":"123456"},function (data) {
                    alert(data);
                },"html");
            });
        });
    </script>
</body>
</html>